use std::{
    fs::{self},
    io,
    path::PathBuf,
};

mod screen_info;

fn main() {
    //ok error 
    let f = err(10);
    match f {
        Ok(k) => println!("{}", k),
        Err(e) => println!("{}", e),
    }

    let (width, height) = screen_info::system_size();
    println!("widht={},heigth={}", width, height);

    let file_list = get_files(String::from("c:/windows/fonts"));
    for i in file_list.into_iter() {
        print!("{:?}\t", &i);
    }
}

fn err(i: i32) -> Result<i32, &'static str> {
    if i == 0 {
        Ok(i)
    } else {
        Err("无效")
    }
}

fn get_files(path: String) -> io::Result<Vec<PathBuf>> {
    let mut entries = fs::read_dir(path)?
        .map(|f| f.map(|m| m.path()))
        .collect::<Result<Vec<_>, io::Error>>()?;
    entries.sort();
    println!("{}个文件",entries.len());
    Ok(entries)
}
